<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>学历分布（男女堆叠）</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
    <style>
        #main {
            width: 900px;
            height: 500px;
            margin: 60px auto;
        }
    </style>
</head>
<body>

<div id="main"></div>

<script>
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);

    const eduLevels = ['大专及以下', '本科', '硕士', '博士'];
    const maleData = [35, 80, 40, 3];
    const femaleData = [25, 70, 40, 7];

    const option = {
        title: {
            text: '学历分布（男女堆叠）',
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: { type: 'shadow' }
        },
        legend: {
            data: ['男性', '女性'],
            top: 30
        },
        grid: {
            left: 60,
            right: 40,
            bottom: 60,
            top: 80
        },
        xAxis: {
            type: 'category',
            data: eduLevels,
            axisLabel: {
                fontSize: 14
            }
        },
        yAxis: {
            type: 'value',
            name: '人数',
            axisLabel: {
                fontSize: 14
            }
        },
        series: [
            {
                name: '男性',
                type: 'bar',
                stack: 'gender',
                label: {
                    show: true,
                    position: 'inside'
                },
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#3a8ee6' },
                        { offset: 1, color: '#70c1ff' }
                    ])
                },
                data: maleData
            },
            {
                name: '女性',
                type: 'bar',
                stack: 'gender',
                label: {
                    show: true,
                    position: 'inside'
                },
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#4cd964' },
                        { offset: 1, color: '#a6f3c5' }
                    ])
                },
                data: femaleData
            }
        ]
    };

    myChart.setOption(option);
</script>

</body>
</html>
